var Demos = [];
var nDemos = 8;

// Demo variables
// iMouseDown represents the current mouse button state: up or down
/*
 * lMouseState represents the previous mouse button state so that we can check
 * for button clicks and button releases:
 * 
 * if(iMouseDown && !lMouseState) // button just clicked! if(!iMouseDown &&
 * lMouseState) // button just released!
 */
var mouseOffset = null;
var iMouseDown = false;
var lMouseState = false;
var dragObject = null;

// Demo 0 variables
var DragDrops = [];
var curTarget = null;
var lastTarget = null;
var dragHelper = null;
var tempDiv = null;
var rootParent = null;
var rootSibling = null;
var nImg = new Image();

nImg.src = 'images/drag_drop_poof.gif';

// Demo1 variables
var D1Target = null;

Number.prototype.NaN0 = function() {
	return isNaN(this) ? 0 : this;
}

function CreateDragContainer() {
	/*
	 * Create a new "Container Instance" so that items from one "Set" can not be
	 * dragged into items from another "Set"
	 */
	var cDrag = DragDrops.length;
	DragDrops[cDrag] = [];

	/*
	 * Each item passed to this function should be a "container". Store each of
	 * these items in our current container
	 */
	for (var i = 0; i < arguments.length; i++) {
		var cObj = arguments[i];
		DragDrops[cDrag].push(cObj);
		cObj.setAttribute('DropObj', cDrag);

		/*
		 * Every top level item in these containers should be draggable. Do this
		 * by setting the DragObj attribute on each item and then later checking
		 * this attribute in the mouseMove function
		 */
		for (var j = 0; j < cObj.childNodes.length; j++) {

			// Firefox puts in lots of #text nodes...skip these
			if (cObj.childNodes[j].nodeName == '#text')
				continue;

			cObj.childNodes[j].setAttribute('DragObj', cDrag);
		}
	}
}

function getPosition(e) {
	var left = 0;
	var top = 0;
	while (e.offsetParent) {
		left += e.offsetLeft
				+ (e.currentStyle ? (parseInt(e.currentStyle.borderLeftWidth))
						.NaN0() : 0);
		top += e.offsetTop
				+ (e.currentStyle ? (parseInt(e.currentStyle.borderTopWidth))
						.NaN0() : 0);
		e = e.offsetParent;
	}

	left += e.offsetLeft
			+ (e.currentStyle ? (parseInt(e.currentStyle.borderLeftWidth))
					.NaN0() : 0);
	top += e.offsetTop
			+ (e.currentStyle ? (parseInt(e.currentStyle.borderTopWidth))
					.NaN0() : 0);

	return {
		x : left,
		y : top
	};

}

function mouseCoords(ev) {
	if (ev.pageX || ev.pageY) {
		return {
			x : ev.pageX,
			y : ev.pageY
		};
	}
	return {
		x : ev.clientX + document.body.scrollLeft - document.body.clientLeft,
		y : ev.clientY + document.body.scrollTop - document.body.clientTop
	};
}

function writeHistory(object, message) {
	if (!object || !object.parentNode || !object.parentNode.getAttribute)
		return;
	var historyDiv = object.parentNode.getAttribute('history');
	if (historyDiv) {
		historyDiv = document.getElementById(historyDiv);
		historyDiv.appendChild(document.createTextNode(object.id + ': '
				+ message));
		historyDiv.appendChild(document.createElement('BR'));

		historyDiv.scrollTop += 50;
	}
}

function getMouseOffset(target, ev) {
	ev = ev || window.event;

	var docPos = getPosition(target);
	var mousePos = mouseCoords(ev);
	return {
		x : mousePos.x - docPos.x,
		y : mousePos.y - docPos.y
	};
}

function mouseMove(ev) {
	ev = ev || window.event;
    try{
	/*
	 * We are setting target to whatever item the mouse is currently on
	 * 
	 * Firefox uses event.target here, MSIE uses event.srcElement
	 */
	var target = ev.target || ev.srcElement;
	var mousePos = mouseCoords(ev);

	if (Demos[0] || Demos[4]) {
		// mouseOut event - fires if the item the mouse is on has changed
		if (lastTarget && (target !== lastTarget)) {
			writeHistory(lastTarget, 'Mouse Out Fired');

			// reset the classname for the target element
			var origClass = lastTarget.getAttribute('origClass');
			if (origClass)
				lastTarget.className = origClass;
		}

		/*
		 * dragObj is the grouping our item is in (set from the
		 * createDragContainer function). if the item is not in a grouping we
		 * ignore it since it can't be dragged with this script.
		 */
		var dragObj = target.getAttribute('DragObj');

		// if the mouse was moved over an element that is draggable
		if (dragObj != null) {

			// mouseOver event - Change the item's class if necessary
			if (target != lastTarget) {
				writeHistory(target, 'Mouse Over Fired');

				var oClass = target.getAttribute('overClass');

				if (oClass) {
					target.setAttribute('origClass', target.className);
					target.className = oClass;
				}
			}

			// if the user is just starting to drag the element
			if (iMouseDown && !lMouseState) {
				writeHistory(target, 'Start Dragging');

				// mouseDown target
				curTarget = target;

				// Record the mouse x and y offset for the element
				rootParent = curTarget.parentNode;
				rootSibling = curTarget.nextSibling;

				mouseOffset = getMouseOffset(target, ev);

				// We remove anything that is in our dragHelper DIV so we can
				// put a new item in it.
				for (var i = 0; i < dragHelper.childNodes.length; i++)
					dragHelper.removeChild(dragHelper.childNodes[i]);

				// Make a copy of the current item and put it in our drag
				// helper.
				dragHelper.appendChild(curTarget.cloneNode(true));
				dragHelper.style.display = 'block';

				// set the class on our helper DIV if necessary
				var dragClass = curTarget.getAttribute('dragClass');
				if (dragClass) {
					dragHelper.firstChild.className = dragClass;
				}

				// disable dragging from our helper DIV (it's already being
				// dragged)
				dragHelper.firstChild.removeAttribute('DragObj');

				/*
				 * Record the current position of all drag/drop targets related
				 * to the element. We do this here so that we do not have to do
				 * it on the general mouse move event which fires when the mouse
				 * moves even 1 pixel. If we don't do this here the script would
				 * run much slower.
				 */
				var dragConts = DragDrops[dragObj];

				/*
				 * first record the width/height of our drag item. Then hide it
				 * since it is going to (potentially) be moved out of its
				 * parent.
				 */
				curTarget.setAttribute('startWidth',
						parseInt(curTarget.offsetWidth));
				curTarget.setAttribute('startHeight',
						parseInt(curTarget.offsetHeight));
				curTarget.style.display = 'none';

				// loop through each possible drop container
				for (var i = 0; i < dragConts.length; i++) {
					with (dragConts[i]) {
						var pos = getPosition(dragConts[i]);

						/*
						 * save the width, height and position of each
						 * container.
						 * 
						 * Even though we are saving the width and height of
						 * each container back to the container this is much
						 * faster because we are saving the number and do not
						 * have to run through any calculations again. Also,
						 * offsetHeight and offsetWidth are both fairly slow.
						 * You would never normally notice any performance hit
						 * from these two functions but our code is going to be
						 * running hundreds of times each second so every little
						 * bit helps!
						 * 
						 * Note that the biggest performance gain here, by far,
						 * comes from not having to run through the getPosition
						 * function hundreds of times.
						 */
						setAttribute('startWidth', parseInt(offsetWidth));
						setAttribute('startHeight', parseInt(offsetHeight));
						setAttribute('startLeft', pos.x);
						setAttribute('startTop', pos.y);
					}

					// loop through each child element of each container
					for (var j = 0; j < dragConts[i].childNodes.length; j++) {
						with (dragConts[i].childNodes[j]) {
							if ((nodeName == '#text')
									|| (dragConts[i].childNodes[j] == curTarget))
								continue;

							var pos = getPosition(dragConts[i].childNodes[j]);

							// save the width, height and position of each
							// element
							setAttribute('startWidth', parseInt(offsetWidth));
							setAttribute('startHeight', parseInt(offsetHeight));
							setAttribute('startLeft', pos.x);
							setAttribute('startTop', pos.y);
						}
					}
				}
			}
		}

		// If we get in here we are dragging something
		if (curTarget) {
			// move our helper div to wherever the mouse is (adjusted by
			// mouseOffset)
			dragHelper.style.top = mousePos.y - mouseOffset.y;
			dragHelper.style.left = mousePos.x - mouseOffset.x;

			var dragConts = DragDrops[curTarget.getAttribute('DragObj')];
			var activeCont = null;

			var xPos = mousePos.x - mouseOffset.x
					+ (parseInt(curTarget.getAttribute('startWidth')) / 2);
			var yPos = mousePos.y - mouseOffset.y
					+ (parseInt(curTarget.getAttribute('startHeight')) / 2);

			// check each drop container to see if our target object is "inside"
			// the container
			for (var i = 0; i < dragConts.length; i++) {
				with (dragConts[i]) {
					if ((parseInt(getAttribute('startLeft')) < xPos)
							&& (parseInt(getAttribute('startTop')) < yPos)
							&& ((parseInt(getAttribute('startLeft')) + parseInt(getAttribute('startWidth'))) > xPos)
							&& ((parseInt(getAttribute('startTop')) + parseInt(getAttribute('startHeight'))) > yPos)) {

						/*
						 * our target is inside of our container so save the
						 * container into the activeCont variable and then exit
						 * the loop since we no longer need to check the rest of
						 * the containers
						 */
						activeCont = dragConts[i];

						// exit the for loop
						break;
					}
				}
			}

			// Our target object is in one of our containers. Check to see where
			// our div belongs
			if (activeCont) {
				if (activeCont != curTarget.parentNode) {
					writeHistory(curTarget, 'Moved into ' + activeCont.id);
				}

				// beforeNode will hold the first node AFTER where our div
				// belongs
				var beforeNode = null;

				// loop through each child node (skipping text nodes).
				for (var i = activeCont.childNodes.length - 1; i >= 0; i--) {
					with (activeCont.childNodes[i]) {
						if (nodeName == '#text')
							continue;

						// if the current item is "After" the item being dragged
						if (curTarget != activeCont.childNodes[i]
								&& ((parseInt(getAttribute('startLeft')) + parseInt(getAttribute('startWidth'))) > xPos)
								&& ((parseInt(getAttribute('startTop')) + parseInt(getAttribute('startHeight'))) > yPos)) {
							beforeNode = activeCont.childNodes[i];
						}
					}
				}

				// the item being dragged belongs before another item
				if (beforeNode) {
					if (beforeNode != curTarget.nextSibling) {
						writeHistory(curTarget, 'Inserted Before '
										+ beforeNode.id);

						activeCont.insertBefore(curTarget, beforeNode);
					}

					// the item being dragged belongs at the end of the current
					// container
				} else {
					if ((curTarget.nextSibling)
							|| (curTarget.parentNode != activeCont)) {
						writeHistory(curTarget, 'Inserted at end of '
										+ activeCont.id);

						activeCont.appendChild(curTarget);
					}
				}

				// the timeout is here because the container doesn't
				// "immediately" resize
				setTimeout(function() {
							var contPos = getPosition(activeCont);
							activeCont.setAttribute('startWidth',
									parseInt(activeCont.offsetWidth));
							activeCont.setAttribute('startHeight',
									parseInt(activeCont.offsetHeight));
							activeCont.setAttribute('startLeft', contPos.x);
							activeCont.setAttribute('startTop', contPos.y);
						}, 5);

				// make our drag item visible
				if (curTarget.style.display != '') {
					writeHistory(curTarget, 'Made Visible');
					curTarget.style.display = '';
					curTarget.style.visibility = 'hidden';
				}
			} else {

				// our drag item is not in a container, so hide it.
				if (curTarget.style.display != 'none') {
					writeHistory(curTarget, 'Hidden');
					curTarget.style.display = 'none';
				}
			}
		}

		// track the current mouse state so we can compare against it next time
		lMouseState = iMouseDown;

		// mouseMove target
		lastTarget = target;
	}

	if (dragObject) {
		dragObject.style.position = 'absolute';
		dragObject.style.top = mousePos.y - mouseOffset.y;
		dragObject.style.left = mousePos.x - mouseOffset.x;
	}

	// track the current mouse state so we can compare against it next time
	lMouseState = iMouseDown;

	// this prevents items on the page from being highlighted while dragging
	if (curTarget || dragObject)
		return false;
    }catch(error){}	
}

function mouseUp(ev) {

	if (Demos[0] || Demos[4]) {
		if (curTarget) {
			writeHistory(curTarget, 'Mouse Up Fired');

			dragHelper.style.display = 'none';
			if (curTarget.style.display == 'none') {
				if (rootSibling) {
					rootParent.insertBefore(curTarget, rootSibling);
				} else {
					rootParent.appendChild(curTarget);
				}
			}
			curTarget.style.display = '';
			curTarget.style.visibility = 'visible';
		}
		curTarget = null;
	}
	if (Demos[6] && dragObject) {
		ev = ev || window.event;
		var mousePos = mouseCoords(ev);

		var dT = dragObject.getAttribute('droptarget');
		if (dT) {
			var targObj = document.getElementById(dT);
			var objPos = getPosition(targObj);
			if ((mousePos.x > objPos.x)
					&& (mousePos.y > objPos.y)
					&& (mousePos.x < (objPos.x + parseInt(targObj.offsetWidth)))
					&& (mousePos.y < (objPos.y + parseInt(targObj.offsetHeight)))) {
				var nSrc = targObj.getAttribute('newSrc');
				if (nSrc) {
					dragObject.src = nSrc;
					setTimeout(function() {
								if (!dragObject || !dragObject.parentNode)
									return;
								dragObject.parentNode.removeChild(dragObject);
								dragObject = null;
							}, parseInt(targObj.getAttribute('timeout')));
				} else {
					dragObject.parentNode.removeChild(dragObject);
				}
			}
		}
	}

	dragObject = null;

	iMouseDown = false;
}

function mouseDown(ev) {
	ev = ev || window.event;
	try{
	var target = ev.target || ev.srcElement;

	iMouseDown = true;
	if (Demos[0] || Demos[4]) {
		if (lastTarget) {
			writeHistory(lastTarget, 'Mouse Down Fired');
		}
	}
	if (target.onmousedown || target.getAttribute('DragObj')) {
		return false;
	}
	}catch(error){}
}

function makeDraggable(item) {
	if (!item)
		return;
	item.onmousedown = function(ev) {
		dragObject = this;
		mouseOffset = getMouseOffset(this, ev);
		return false;
	}
}

function makeClickable(item) {
	if (!item)
		return;
	item.onmousedown = function(ev) {
		document.getElementById('ClickImage').value = this.name;
	}
}

function addDropTarget(item, target) {
	item.setAttribute('droptarget', target);
}

document.onmousemove = mouseMove;
document.onmousedown = mouseDown;
document.onmouseup = mouseUp;

function init(c) {
	for (var i = 0; i < nDemos; i++) {
		Demos[i] = document.getElementById('Demo' + i);
	}

	if (Demos[4]) {
		CreateDragContainer(document.getElementById('DragContainer1'));
	}
	if (Demos[0] || Demos[4]) {
		// Create our helper object that will show the item while dragging
		dragHelper = document.createElement('DIV');
		dragHelper.style.cssText = 'position:absolute;display:none;';

		document.body.appendChild(dragHelper);
	}

	/* 设置计数器 */
	count = c;
}

// 可以打包为js文件;
var x0 = 0, y0 = 0, x1 = 0, y1 = 0;
var offx = 6, offy = 6;
var moveable = false;
var hover = 'orange', normal = '#336699';// color;
var index = 99;// z-index;
// 开始拖动;
function startDrag(obj) {
	if (event.button == 1) {
		// 锁定标题栏;
		obj.setCapture();
		// 定义对象;
		var win = obj.parentNode;
		var sha = win.nextSibling;
		// 记录鼠标和层位置;
		x0 = event.clientX;
		y0 = event.clientY;
		x1 = parseInt(win.style.left);
		y1 = parseInt(win.style.top);
		// 记录颜色;
		normal = obj.style.backgroundColor;
		// 改变风格;
		obj.style.backgroundColor = hover;
		win.style.backgroundColor = hover;
		win.style.borderColor = hover;
		obj.nextSibling.style.color = hover;
		sha.style.left = x1 + offx;
		sha.style.top = y1 + offy;
		moveable = true;
	}
}
// 拖动;
function drag(obj) {
	if (moveable) {
		var win = obj.parentNode;
		var sha = win.nextSibling;

		win.style.left = x1 + event.clientX - x0;
		win.style.top = y1 + event.clientY - y0;

		if (parseInt(win.style.left) < "0") {
			win.style.left = "0px";
		}
		if (parseInt(win.style.top) < "0") {
			win.style.top = "0px";
		}

		sha.style.left = parseInt(win.style.left) + offx;
		sha.style.top = parseInt(win.style.top) + offy;
	}
}
// 停止拖动;
function stopDrag(obj) {
	if (moveable) {
		var win = obj.parentNode;
		var sha = win.nextSibling;
		var msg = obj.nextSibling;
		win.style.borderColor = normal;
		win.style.backgroundColor = normal;
		obj.style.backgroundColor = normal;
		msg.style.color = normal;
		sha.style.left = obj.parentNode.style.left;
		sha.style.top = obj.parentNode.style.top;
		obj.releaseCapture();
		moveable = false;
	}
}
// 获得焦点;
function getFocus(obj) {
	if (obj.style.zIndex != index) {
		index = index + 2;
		var idx = index;
		obj.style.zIndex = idx;
		obj.nextSibling.style.zIndex = idx - 1;
	}
}
// 最小化;
function min(obj) {
	var win = obj.parentNode.parentNode;
	var sha = win.nextSibling;
	var tit = obj.parentNode;
	var msg = tit.nextSibling;
	var flg = msg.style.display == "none";
	if (flg) {
		win.style.height = parseInt(msg.style.height)
				+ parseInt(tit.style.height) + 2 * 2;
		sha.style.height = win.style.height;
		msg.style.display = "block";
		obj.innerHTML = "0";
	} else {
		win.style.height = parseInt(tit.style.height) + 2 * 2;
		sha.style.height = win.style.height;
		obj.innerHTML = "2";
		msg.style.display = "none";
	}
}
// 创建一个对象;
function xWin(id, w, h, l, t, tit, msg) {
	index = index + 2;
	this.id = id;
	this.width = w;
	this.height = h;
	this.left = l;
	this.top = t;
	this.zIndex = index;
	this.title = tit;
	this.message = msg;
	this.obj = null;
	this.bulid = bulid;

	this.bulid();
}
// 初始化;
function bulid() {
	var str = ""
			+ "<div id=xMsg"
			+ this.id
			+ " "
			+ "style='"
			+ "z-index:"
			+ this.zIndex
			+ ";"
			+ "width:"
			+ this.width
			+ ";"
			+ "height:"
			+ this.height
			+ ";"
			+ "left:"
			+ this.left
			+ ";"
			+ "top:"
			+ this.top
			+ ";"
			+ "background-color:"
			+ normal
			+ ";"
			+ "color:"
			+ normal
			+ ";"
			+ "font-size:8pt;"
			+ "font-family:Tahoma;"
			+ "position:absolute;"
			+ "cursor:default;"
			+ "display:none;"
			+ "border:1px solid "
			+ normal
			+ ";"
			+ "' "
			+ "onmousedown='getFocus(this)'>"
			+ "<div "
			+ "style='"
			+ "background-color:"
			+ normal
			+ ";"
			+ "width:"
			+ (this.width + 2 * 2)
			+ ";"
			+ "height:20;"
			+ "color:white;"
			+ "' "
			+ "onmousedown='startDrag(this)' "
			+ "onmouseup='stopDrag(this)' "
			+ "onmousemove='drag(this)' "
			+ ">"
			+ "<table border='0' width='100%' cellspacing='0' cellpadding='0'><tr><td align='left' width='50%'><span style='width:"
			+ (this.width - 2 * 12 - 4)
			+ ";padding-left:3px;color:white;'>"
			+ this.title
			+ "</span></td>"
			+ "<td align='right' width='50%'>"
			+ "<span style='width:12;border-width:0px;color:white;font-family:webdings;' title='关闭' onclick='closeWin(\""
			+ this.id + "\")'>r</span></td></tr></table>" + "</div>"
			+ "<div id=xContent" + this.id + " style='" + "width:100%;"
			+ "height:" + (this.height - 20 - 4) + ";"
			+ "background-color:white;" + "overflow:auto;"
			+ "SCROLLBAR-FACE-COLOR: #ffffff;"
			+ "SCROLLBAR-HIGHLIGHT-COLOR: #ffffff;"
			+ "SCROLLBAR-SHADOW-COLOR: #ffffff;"
			+ "SCROLLBAR-3DLIGHT-COLOR: #ffffff;"
			+ "SCROLLBAR-ARROW-COLOR: #ff9966;"
			+ "SCROLLBAR-DARKSHADOW-COLOR: #ffffff;" + "line-height:14px;"
			+ "word-break:break-all;" + "padding:3px;" + "'>" + this.message
			+ "</div>" + "</div>" + "<div id=xMsg" + this.id + "bg style='"
			+ "width:" + this.width + ";" + "height:" + this.height + ";"
			+ "top:" + this.top + ";" + "left:" + this.left + ";" + "z-index:"
			+ (this.zIndex - 1) + ";" + "position:absolute;" + "display:none;"
			+ "background-color:black;" + "filter:alpha(opacity=40);"
			+ "'></div>";
	// alert(document.body);
	document.forms[0].insertAdjacentHTML("beforeEnd", str);

}

// 显示窗口
function showWin(id) {
	document.getElementById("xMsg" + id).style.display = "block";
	document.getElementById("xMsg" + id + "bg").style.display = "block";
}

// 隐藏窗口
function closeWin(id) {
	document.getElementById("xMsg" + id).style.display = "none";
	document.getElementById("xMsg" + id + "bg").style.display = "none";
}

/** **工具栏*** */
function initializeToolbar(id, title, str) {
	if (!document.getElementById("xMsg" + id)) {
		var temp = "<iframe id=\"toolbartree\" frameborder=\"0\" width=\"100%\" ";
		temp += "height=\"100%\" src=\"\"></iframe>";

		var tree = new xWin(id, 400, 400, 50, 10, title, temp);
	}

	var url = "xtree.do?method=show&file=/xsystem/software/design/showDesign.properties&id="
			+ str;
	toolbartree.location.href = url;

	showWin(id);
}

function createToolbar() {
	var itemDiv = document.createElement("div");
	itemDiv.className = "DragBox";
	itemDiv.id = "item_" + count;
	itemDiv.setAttribute('overClass', 'OverDragBox');
	itemDiv.setAttribute('dragClass', 'DragDragBox');
	itemDiv.setAttribute('dragObj', '0');
	// itemDiv.style.height = "20px";
	itemDiv.style.width = "300px";
	itemDiv.style.fontSize = "12";

	var str = "";
	str += "<div class=\"divn\">工具栏名称:&nbsp;<input type='text' class='box3' name='tname_"
			+ count + "' value=''></div>";
	str += "<div class=\"divn\">工具栏描述:&nbsp;<input type='text' class='box3' name='tmemo_"
			+ count + "' value=''>&nbsp;&nbsp;";
	str += "<input type='hidden' name='ttaxis_" + count + "' value='0'></div>";
	str += "<div class=\"divn\">&nbsp;</div>";
	str += '<div class=\"divn\" align="right"><span title="删除" onclick="deleteRow(\'item_'
			+ count + '\');"><font color="#006699">删除</font>';
	str += "</span></div>";

	itemDiv.innerHTML = str;

	count++;

	DragContainer1.appendChild(itemDiv);
}

function createMenu() {
	var itemDiv = document.createElement("div");
	itemDiv.className = "DragBox";
	itemDiv.id = "item_" + count;
	itemDiv.setAttribute('overClass', 'OverDragBox');
	itemDiv.setAttribute('dragClass', 'DragDragBox');
	itemDiv.setAttribute('dragObj', '0');
	// itemDiv.style.height = "20px";
	itemDiv.style.width = "700px";
	itemDiv.style.fontSize = "12";

	var str = "<input type='hidden' name='mnid_" + count + "' value=''>";
	str += "<div class=\"divn\">菜单项&nbsp;<span title=\"删除菜单项\" onclick=\"deleteRow(\'item_"
			+ count
			+ "\',-1);\"><font color=\"#006699\">删 除</font></span></div>";
	str += "<div class=\"divn\">菜单名称:&nbsp;<input type='text' class='box3' style='width:500px' name='mnname_"
			+ count + "' value=''></div>";
	str += "<div class=\"divn\">菜单链接:&nbsp;<input type='text' class='box3' style='width:500px' name='mnurl_"
			+ count + "' value=''>";
	str += "</div>";
	/*
	 * str += "<div>访问权限:&nbsp;"; str += "<div
	 * onclick=\"javascript:handleSelect(this);\" title=\"点击选择\"
	 * id=\"names"+count+"\" "; str +=
	 * "style=\"height:30px;width:200px;border-bottom : 1px #6199C5 solid;\"></div>";
	 * str += "</div>";
	 */
	str += "<div class=\"divn\">菜单描述:&nbsp;<input type='text' class='box3' style='width:500px' name='mnmemo_"
			+ count + "' value=''></div>";
	str += "<div class=\"divn\">&nbsp;</div>";

	itemDiv.innerHTML = str;

	count++;

	DragContainer1.appendChild(itemDiv);
}

function createBlank() {
	var itemDiv = document.createElement("div");
	itemDiv.className = "DragBox";
	itemDiv.id = "item_" + count;
	itemDiv.setAttribute('overClass', 'OverDragBox');
	itemDiv.setAttribute('dragClass', 'DragDragBox');
	itemDiv.setAttribute('dragObj', '0');
	itemDiv.style.height = "20px";
	itemDiv.style.width = "400px";
	itemDiv.style.fontSize = "12";

	var str = "";
	str += "<div>空白项&nbsp;<input type='hidden' name='iblank_" + count
			+ "' value='1'></div>";
	str += "<input type='hidden' name='iname_" + count + "' value=''>";
	str += "<input type='hidden' name='iurl_" + count + "' value=''>";
	str += "<input type='hidden' name='iurltype_" + count + "' value='0'>";
	str += "<input type='hidden' name='ievent_" + count + "' value=''>";
	str += "<input type='hidden' name='iplug_" + count + "' value=''>";
	str += "<input type='hidden' name='imemo_" + count + "' value=''>";
	str += "<div>&nbsp;</div>";
	str += '<div align="right"><span title="删除" onclick="deleteRow(\'item_'
			+ count + '\',-1);"><font color="#006699">删 除</font>';
	str += "</span>&nbsp;</div>";

	itemDiv.innerHTML = str;

	count++;

	DragContainer1.appendChild(itemDiv);
}

function deleteRow(obj, id) {
	if (confirm("确定删除") == true) {
		if (id != -1) {
			var url = context + "/system/module.do?method=deletemenu&id=" + id;
			var res = sendRequest(url);

			if (res == 1) {
				document.getElementById(obj).removeNode(true);
			} else if (res == 0) {
				alert("请先删除子菜单");
			} else {
				alert("删除菜单项失败");
			}
		} else {
			document.getElementById(obj).removeNode(true);
		}
	}
}

function removeElement(element) {
	// alert(element.parentNode.nodeName);
	element.parentNode.removeNode(element);
	// element.parentNode.removeChild(element);
}

function te2stChange(n) {
	if (!isNaN(n) && n > 0) {
		if (n % 16 == 0) {
			return te2stChange(n / 16) + "0";
		} else {
			if (n > 16) {
				return te2stChange(parseInt(n / 16)) + teMatchst((n % 16), 16);
			} else {
				return te2stChange(0) + teMatchst(n, 16);
			}
		}
	} else {
		return "";
	}
}

function teMatchst(v, rv) {
	if (rv == 16) {
		switch (v.toString()) {
			case "0" :
				return "0";
				break;
			case "1" :
				return "1";
				break;
			case "2" :
				return "2";
				break;
			case "3" :
				return "3";
				break;
			case "4" :
				return "4";
				break;
			case "5" :
				return "5";
				break;
			case "6" :
				return "6";
				break;
			case "7" :
				return "7";
				break;
			case "8" :
				return "8";
				break;
			case "9" :
				return "9";
				break;
			case "10" :
				return "A";
				break;
			case "11" :
				return "B";
				break;
			case "12" :
				return "C";
				break;
			case "13" :
				return "D";
				break;
			case "14" :
				return "E";
				break;
			case "15" :
				return "F";
				break;
			default :
				return "";
				break;
		}
	} else {
		switch (v.toString()) {
			case "0" :
				return "0";
				break;
			case "1" :
				return "1";
				break;
			case "2" :
				return "2";
				break;
			case "3" :
				return "3";
				break;
			case "4" :
				return "4";
				break;
			case "5" :
				return "5";
				break;
			case "6" :
				return "6";
				break;
			case "7" :
				return "7";
				break;
			case "8" :
				return "8";
				break;
			case "9" :
				return "9";
				break;
			case "A" :
				return "10";
				break;
			case "B" :
				return "11";
				break;
			case "C" :
				return "12";
				break;
			case "D" :
				return "13";
				break;
			case "E" :
				return "14";
				break;
			case "F" :
				return "15";
				break;
			default :
				return "";
				break;
		}
	}
}

/** 查询当前页面中的关键字 */
var NS4 = (document.layers);
var IE4 = (document.all);
var win = window;
var n = 0;
function findInPage(str) {
	var txt, i, found;
	if (str == "")
		return false;
	if (NS4) {
		if (!win.find(str))
			while (win.find(str, false, true))
				n++;
		else
			n++;
		if (n == 0)
			alert("没有找到。");
	}
	if (IE4) {
		txt = win.document.body.createTextRange();
		for (i = 0; i <= n && (found = txt.findText(str)) != false; i++) {
			txt.moveStart("character", 1);
			txt.moveEnd("textedit");
		}
		if (found) {
			txt.moveStart("character", -1);
			txt.findText(str);
			txt.select();
			txt.scrollIntoView();
			n++;
		} else {
			if (n > 0) {
				n = 0;
				findInPage(str);
			} else
				alert("没有找到。");
		}
	}
	return false;
}

function handleSave() {
	if (isblank(document.form1.swname)) {
		alert("请定义软件名称");
		return;
	}

	document.form1.oName.value = document.form1.swname.value;
	document.form1.sTitle.value = document.form1.swname.value;

	if (DragContainer1.childNodes.length == 0) {
		if (confirm("不完整的软件安装,确定保存") == true)
			document.form1.submit();
	} else {
		for (var i = 0; i < DragContainer1.childNodes.length; i++) {
			/* ID of div */
			var oid = DragContainer1.childNodes[i].id;
			/* ID of item */
			oid = oid.substring(oid.indexOf("_") + 1, oid.length);
			/* sort of item */
			document.getElementById("ttaxis_" + oid).value = i;
			document.getElementById("count").value += oid + ",";
		}
		document.form1.submit();
	}
}

var urlObject;

function handleRadio(thizz) {
	urlObject = document.getElementsByName(thizz)[0];

	var url = context + "/xsystem/software/autoseturl.jsp";
	dialog(url, true, "自动设置菜单链接", 650, 450);
}

function setURL(url) {
	if (urlObject) {
		urlObject.value = url;
	}
}